use axum::Json;
use serde::{Deserialize, Serialize};
use crate::api::get_sisu::get_sisu_redirect_url;
use crate::db::db_insert::db_insert;

#[derive(Debug, Serialize, Deserialize)]
pub struct SisuLoginUrl {
    url: String,
}

pub async fn get_sisu_login_url() ->Json<SisuLoginUrl> {
    let url = get_sisu_redirect_url().await.unwrap();
    return Json(SisuLoginUrl { url });
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SisuCodeAndState {
    code: String,
    state: String,
}

pub async fn set_sisu_code_and_state(Json(payload): Json<SisuCodeAndState>) {
    let code = payload.code;
    let state = payload.state;
    db_insert("sisu_code", &code).await.unwrap();
    db_insert("sisu_state", &state).await.unwrap();
}